<?php
declare(strict_types=1);
/**
 * MineAdmin is committed to providing solutions for quickly building web applications
 * Please view the LICENSE file that was distributed with this source code,
 * For the full copyright and license information.
 * Thank you very much for using MineAdmin.
 *
 * @Author X.Mo<root@imoi.cn>
 * @Link   https://gitee.com/xmo/MineAdmin
 */

namespace App\Record\Mapper;

use App\Record\Model\RecordPaymentOrder;
use Hyperf\Database\Model\Builder;
use Mine\Abstracts\AbstractMapper;

/**
 * 订单记录Mapper类
 */
class RecordPaymentOrderMapper extends AbstractMapper
{
    /**
     * @var RecordPaymentOrder
     */
    public $model;

    public function assignModel()
    {
        $this->model = RecordPaymentOrder::class;
    }

    /**
     * 搜索处理器
     * @param Builder $query
     * @param array $params
     * @return Builder
     */
    public function handleSearch(Builder $query, array $params): Builder
    {
        
        // 
        if (isset($params['id']) && filled($params['id'])) {
            $query->where('id', '=', $params['id']);
        }

        // 订单号
        if (isset($params['order_sn']) && filled($params['order_sn'])) {
            $query->where('order_sn', '=', $params['order_sn']);
        }

        // 第三方支付单号
        if (isset($params['transaction_id']) && filled($params['transaction_id'])) {
            $query->where('transaction_id', '=', $params['transaction_id']);
        }

        // 用户ID
        if (isset($params['user_id']) && filled($params['user_id'])) {
            $query->where('user_id', '=', $params['user_id']);
        }

        // 优惠券ID
        if (isset($params['coupon_id']) && filled($params['coupon_id'])) {
            $query->where('coupon_id', '=', $params['coupon_id']);
        }

        // 订单金额(分)
        if (isset($params['money']) && filled($params['money'])) {
            $query->where('money', '=', $params['money']);
        }

        // 折扣金额(分)
        if (isset($params['discount']) && filled($params['discount'])) {
            $query->where('discount', '=', $params['discount']);
        }

        // 实付金额(分)
        if (isset($params['fact_money']) && filled($params['fact_money'])) {
            $query->where('fact_money', '=', $params['fact_money']);
        }

        // 到账金额
        if (isset($params['received_amount']) && filled($params['received_amount'])) {
            $query->where('received_amount', '=', $params['received_amount']);
        }

        // 支付方式
        if (isset($params['method_id']) && filled($params['method_id'])) {
            $query->where('method_id', '=', $params['method_id']);
        }

        // ip
        if (isset($params['ip']) && filled($params['ip'])) {
            $query->where('ip', 'like', '%'.$params['ip'].'%');
        }

        // 业务ID
        if (isset($params['biz_id']) && filled($params['biz_id'])) {
            $query->where('biz_id', '=', $params['biz_id']);
        }

        // 业务类型1充值钻石
        if (isset($params['biz_type']) && filled($params['biz_type'])) {
            $query->where('biz_type', '=', $params['biz_type']);
        }

        // 订单完成时间
        if (isset($params['complete_time']) && filled($params['complete_time'])) {
            $query->where('complete_time', '=', $params['complete_time']);
        }

        // 订单超时时间
        if (isset($params['expire_time']) && filled($params['expire_time'])) {
            $query->where('expire_time', '=', $params['expire_time']);
        }

        // 支付成功时间
        if (isset($params['pay_time']) && filled($params['pay_time'])) {
            $query->where('pay_time', '=', $params['pay_time']);
        }

        // 订单状态(0刚下单,1.已回调,2.支付成功,3.订单已关闭)
        if (isset($params['status']) && filled($params['status'])) {
            $query->where('status', '=', $params['status']);
        }

        // 所属代理
        if (isset($params['created_by']) && filled($params['created_by'])) {
            $query->where('created_by', '=', $params['created_by']);
        }

        // 创建时间
        if (isset($params['create_time']) && filled($params['create_time'])) {
            $query->where('create_time', '=', $params['create_time']);
        }

        // 更新时间
        if (isset($params['update_time']) && filled($params['update_time'])) {
            $query->where('update_time', '=', $params['update_time']);
        }

        return $query;
    }
}